<!DOCTYPE html>
<html lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">


<link rel="stylesheet" href="/blog/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/blog/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="系统封装好的进度条弹窗  基本使用123456789ProgressDialog progressDialog &#x3D; new ProgressDialog(this);        progressDialog.setTitle(&quot;标题&quot;);&#x2F;&#x2F;标题        progressDialog.setIcon(R.mipmap.ic_launcher);&#x2F;&#x2F;标题左侧图标        progr">
<meta property="og:type" content="article">
<meta property="og:title" content="ProgressDialog">
<meta property="og:url" content="http://yoursite.com/2017/08/14/ProgressDialog/index.html">
<meta property="og:site_name" content="二松同学">
<meta property="og:description" content="系统封装好的进度条弹窗  基本使用123456789ProgressDialog progressDialog &#x3D; new ProgressDialog(this);        progressDialog.setTitle(&quot;标题&quot;);&#x2F;&#x2F;标题        progressDialog.setIcon(R.mipmap.ic_launcher);&#x2F;&#x2F;标题左侧图标        progr">
<meta property="article:published_time" content="2017-08-14T03:50:33.000Z">
<meta property="article:modified_time" content="2020-06-23T03:08:32.945Z">
<meta property="article:author" content="二松">
<meta property="article:tag" content="android">
<meta property="article:tag" content="dialog">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://yoursite.com/2017/08/14/ProgressDialog/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-Hans'
  };
</script>

  <title>ProgressDialog | 二松同学</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/blog/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">二松同学</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">拥有梦想只是一种智力，实现梦想才是一种能力</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blog/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/blog/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/blog/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/08/14/ProgressDialog/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.jpg">
      <meta itemprop="name" content="二松">
      <meta itemprop="description" content="good good study day day up.">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="二松同学">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          ProgressDialog
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2017-08-14 11:50:33" itemprop="dateCreated datePublished" datetime="2017-08-14T11:50:33+08:00">2017-08-14</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-06-23 11:08:32" itemprop="dateModified" datetime="2020-06-23T11:08:32+08:00">2020-06-23</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/%E6%8A%80%E6%9C%AF%E5%8D%9A%E5%AE%A2/" itemprop="url" rel="index"><span itemprop="name">技术博客</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <blockquote>
<p>系统封装好的进度条弹窗</p>
</blockquote>
<h2 id="基本使用"><a href="#基本使用" class="headerlink" title="基本使用"></a>基本使用</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">ProgressDialog progressDialog = <span class="keyword">new</span> ProgressDialog(<span class="keyword">this</span>);</span><br><span class="line">        progressDialog.setTitle(<span class="string">"标题"</span>);<span class="comment">//标题</span></span><br><span class="line">        progressDialog.setIcon(R.mipmap.ic_launcher);<span class="comment">//标题左侧图标</span></span><br><span class="line">        progressDialog.setMessage(<span class="string">"文本"</span>);<span class="comment">//内容</span></span><br><span class="line">        progressDialog.setCancelable(<span class="keyword">true</span>);<span class="comment">//可以按返回键取消</span></span><br><span class="line">        progressDialog.setCanceledOnTouchOutside(<span class="keyword">true</span>);<span class="comment">//可以点击空白取消</span></span><br><span class="line">        progressDialog.setOnDismissListener(<span class="keyword">null</span>);<span class="comment">//隐藏事件</span></span><br><span class="line">        progressDialog.setOnCancelListener(<span class="keyword">null</span>);<span class="comment">//取消事件</span></span><br><span class="line">        progressDialog.show();<span class="comment">//显示</span></span><br></pre></td></tr></table></figure>

<p>或者简单的写法:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ProgressDialog progressDialog = ProgressDialog.show(<span class="keyword">this</span>, <span class="string">"标题"</span>, <span class="string">"内容"</span>);</span><br></pre></td></tr></table></figure>

<h2 id="进度条"><a href="#进度条" class="headerlink" title="进度条"></a>进度条</h2><h3 id="样式"><a href="#样式" class="headerlink" title="样式"></a>样式</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);<span class="comment">//水平</span></span><br><span class="line">progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);<span class="comment">//环形</span></span><br></pre></td></tr></table></figure>

<h3 id="水平进度条"><a href="#水平进度条" class="headerlink" title="水平进度条"></a>水平进度条</h3><ul>
<li><p>进度</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//进度图片</span></span><br><span class="line">progressDialog.setProgressDrawable(getResources().getDrawable(R.mipmap.ic_launcher));</span><br><span class="line"><span class="comment">//最大进度</span></span><br><span class="line">progressDialog.setMax(<span class="number">120</span>);</span><br><span class="line">progressDialog.getMax();</span><br><span class="line"><span class="comment">//设置进度,在show()之后调用</span></span><br><span class="line">progressDialog.setProgress(<span class="number">50</span>);<span class="comment">//设置的是max的多少份</span></span><br><span class="line">progressDialog.getProgress();</span><br><span class="line"><span class="comment">//50/120=42%</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>次要进度</p>
<blockquote>
<p>比如下载或者视频的缓存</p>
<p>颜色比进度要浅一点</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">progressDialog.setSecondaryProgress(<span class="number">80</span>);</span><br><span class="line">progressDialog.getSecondaryProgress();</span><br></pre></td></tr></table></figure>
</li>
<li><p>进度增长设置</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//实际进度加10</span></span><br><span class="line">progressDialog.incrementProgressBy(<span class="number">10</span>);</span><br><span class="line">progressDialog.incrementSecondaryProgressBy(<span class="number">10</span>);</span><br></pre></td></tr></table></figure>
</li>
<li><p>不确定状态进度条</p>
<blockquote>
<p>其实就不显示具体的进度,而是暂时一个加载的动画</p>
<p>常用于一些耗时操作</p>
<p>注意:设置进度是不起作用的,永远是0</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//开启</span></span><br><span class="line">progressDialog.setIndeterminate(<span class="keyword">true</span>);</span><br><span class="line"><span class="comment">//判断  </span></span><br><span class="line">progressDialog.isIndeterminate();</span><br><span class="line"><span class="comment">//不确定进度的图片</span></span><br><span class="line">progressDialog.setIndeterminateDrawable(getResources().getDrawable(R.mipmap.ic_launcher));</span><br></pre></td></tr></table></figure>
</li>
<li><p>格式化进度数字</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//%1d: 当前进度百分比</span></span><br><span class="line"><span class="comment">//%2d: 最大进度百分比</span></span><br><span class="line"><span class="comment">//设置进度比的格式 </span></span><br><span class="line">progressDialog.setProgressNumberFormat(<span class="string">"%1dkb/%2dkb"</span>);</span><br><span class="line"><span class="comment">// getCurrencyInstance 是一个货币格式化的方法</span></span><br><span class="line"><span class="comment">//设置进度格式</span></span><br><span class="line">dialog.setProgressPercentFormat(NumberFormat.getCurrencyInstance());</span><br></pre></td></tr></table></figure>

<p>​</p>
</li>
</ul>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/blog/tags/android/" rel="tag"># android</a>
              <a href="/blog/tags/dialog/" rel="tag"># dialog</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blog/2017/08/14/AlertDialog/" rel="prev" title="AlertDialog">
      <i class="fa fa-chevron-left"></i> AlertDialog
    </a></div>
      <div class="post-nav-item">
    <a href="/blog/2017/08/25/gradle/" rel="next" title="gradle">
      gradle <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#基本使用"><span class="nav-number">1.</span> <span class="nav-text">基本使用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#进度条"><span class="nav-number">2.</span> <span class="nav-text">进度条</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#样式"><span class="nav-number">2.1.</span> <span class="nav-text">样式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#水平进度条"><span class="nav-number">2.2.</span> <span class="nav-text">水平进度条</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="二松"
      src="/blog/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">二松</p>
  <div class="site-description" itemprop="description">good good study day day up.</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">27</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/blog/categories/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/blog/tags/">
          
        <span class="site-state-item-count">32</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">二松</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/blog/lib/anime.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>

<script src="/blog/js/utils.js"></script>

<script src="/blog/js/motion.js"></script>


<script src="/blog/js/schemes/pisces.js"></script>


<script src="/blog/js/next-boot.js"></script>




  













<script>
if (document.querySelectorAll('pre.mermaid').length) {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js', () => {
    mermaid.initialize({
      theme    : 'forest',
      logLevel : 3,
      flowchart: { curve     : 'linear' },
      gantt    : { axisFormat: '%m/%d/%Y' },
      sequence : { actorMargin: 50 }
    });
  }, window.mermaid);
}
</script>


  

  

</body>
</html>
